package com.hua.api.modules.order.rest;

import com.alibaba.fastjson.JSONObject;
import com.hua.api.core.constants.Status;
import com.hua.api.core.framework.annotation.AnonymousAccess;
import com.hua.api.core.framework.annotation.TokenCheck;
import com.hua.api.core.framework.config.scurity.TokenHelper;
import com.hua.api.core.framework.util.Result;
import com.hua.api.modules.order.service.OrderBidService;
import com.hua.api.modules.order.service.dto.OrderBidDto;
import com.hua.api.modules.order.service.dto.OrderBidQueryCriteria;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/orderBid")
public class OrderBidController {

    private final OrderBidService orderBidService;



    /**
     * 创建订单直接转单
     * */
    // @AnonymousAccess
    @RequestMapping("/change/{shopId}")
    @TokenCheck(userAgent = "orderBidChange",source = { Status.admin })
    public Result change(@PathVariable Integer shopId, OrderBidDto dto){
        orderBidService.change(shopId,dto,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    /**
     * 创建订单转单
     * */
    @RequestMapping("/create")
    @TokenCheck(userAgent = "orderBidCreate",source = { Status.admin })
    public Result create(@RequestBody OrderBidDto dto){
       System.out.print("/api/orderBid/create:"+JSONObject.toJSON(dto).toString());
       orderBidService.orderBidCreate(dto,TokenHelper.getUserInfo().getUserId());
       return Result.success();
    }

    /**
     * 取消订单转单
     * */
    @RequestMapping("/cancel")
    @TokenCheck(userAgent = "orderBidCancel",source = { Status.admin })
    public Result cancel(Integer id){
        orderBidService.orderBidCancel(id,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    /**
     * 选择转单店铺
     * */
    @RequestMapping("/winner")
    @TokenCheck(userAgent = "orderBidWinner",source = { Status.admin })
    public Result choseWinner(Integer orderBidItemId){
        orderBidService.chooseWinner(orderBidItemId);
        return Result.success();
    }

    /**
     * 店铺报价
     * */
    @PostMapping("/bidPrice")
    @TokenCheck(userAgent = "orderBidPrice",source = { Status.store })
    public Result bindPrice(@RequestBody OrderBidQueryCriteria criteria){
        orderBidService.bidPrice(criteria,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    /**
     * 店铺报价
     * */
    @PostMapping("/bidCancel")
    @TokenCheck(userAgent = "orderBidCancel",source = { Status.store })
    public Result bindCancel(@RequestBody OrderBidQueryCriteria criteria){
        orderBidService.bidCancel(criteria,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    /**
     * 店铺接单
     * */
    @PostMapping("/jiedan")
    @TokenCheck(userAgent = "orderBidJieDan",source = { Status.store })
    public Result jiedan(@RequestBody OrderBidQueryCriteria criteria){
        orderBidService.jiedan(criteria,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    /**
     * 已接单 订单取消
     * */
    @RequestMapping("/jiedan/cancel/{itemId}")
    @TokenCheck(userAgent = "orderBidJieDanCancel",source = { Status.store, Status.admin })
    public Result jiedanCancel(@PathVariable Integer itemId){
        orderBidService.jiedanCancel(itemId,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

    @RequestMapping("/jiedan/getFineMoney//{itemId}")
    @TokenCheck(userAgent = "getFineMoney",source = { Status.store, Status.admin })
    public Result getFineMoney(@PathVariable Integer itemId){
        return Result.of(orderBidService.getFineMoney(itemId));
    }






























}
